<?php

// 设置脚本类型
header('content-type:application/json;charset=UTF-8');
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "student_01";

// 创建数据库连接
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT date, salary FROM salary WHERE emp_id = 1 ORDER BY date";
$query = mysqli_query($conn, $sql);
$data = mysqli_fetch_all($query);

print_r($data);
$yData = [];
$xData = [];

foreach ($data as $value) {
    array_push($yData, $value['0']);
    array_push($xData, $value['1']);
}

echo json_encode(['code' => 1, 'msg' => '查询成功', 'data' => [
    'salary' => $yData,
    'date' => $xData
]
]);
